import { useState, createContext, useContext } from "react"
const myContext = createContext()

export default function Index() {


    const [msg, setMsg] = useState('index中的数据')
    return (
        <myContext.Provider value={msg}>
            <A />
        </myContext.Provider>
    )
}

function A() {
    return (
        <div>
            <B />
        </div>
    )
}

function B() {
    const msg = useContext(myContext)
    return (
        <div>B</div>
    )
}